package com.ruoyi.develop.goodsOrderMaterials.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.goodsOrderMaterials.domain.GoodsOrderMaterials;
import com.ruoyi.develop.goodsOrderMaterials.service.IGoodsOrderMaterialsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存产品拆解物料配置Controller
 * @author qh
 * @date 2025-03-13
 */
@RestController
@RequestMapping("/goodsOrderMaterials/goodsOrderMaterials")
public class GoodsOrderMaterialsController extends BaseController {
    @Autowired
    private IGoodsOrderMaterialsService goodsOrderMaterialsService;

    /**
     * 查询库存产品拆解物料配置列表
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsOrderMaterials:query')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsOrderMaterials entity) {
        startPage();
        List<GoodsOrderMaterials> list = goodsOrderMaterialsService.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出库存产品拆解物料配置列表
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsOrderMaterials:export')")
    @Log(title = "库存产品拆解物料配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsOrderMaterials entity) {
        List<GoodsOrderMaterials> list = goodsOrderMaterialsService.selectList(entity);
        ExcelUtil<GoodsOrderMaterials> util = new ExcelUtil<GoodsOrderMaterials>(GoodsOrderMaterials. class);
        util.exportExcel(response, list, "库存产品拆解物料配置数据");
    }

    /**
     * 获取库存产品拆解物料配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsOrderMaterials:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(goodsOrderMaterialsService.selectById(id));
    }

    /**
     * 新增库存产品拆解物料配置
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsOrderMaterials:add')")
    @Log(title = "库存产品拆解物料配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody GoodsOrderMaterials entity) {
        return toAjax(goodsOrderMaterialsService.insert(entity));
    }

    @PreAuthorize("@ss.hasPermi('develop:GoodsOrderMaterials:add')")
    @Log(title = "库存产品拆解物料配置", businessType = BusinessType.INSERT)
    @PostMapping("/insertForOrderMaterial")
    public AjaxResult insertForOrderMaterial(@RequestBody GoodsOrderMaterials entity) {
        goodsOrderMaterialsService.insertForOrderMaterial(entity);
        return AjaxResult.success("选择完成！");
    }
    /**
     * 修改库存产品拆解物料配置
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsOrderMaterials:edit')")
    @Log(title = "库存产品拆解物料配置", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody GoodsOrderMaterials entity) {
        return toAjax(goodsOrderMaterialsService.update(entity));
    }

    /**
     * 删除库存产品拆解物料配置
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsOrderMaterials:remove')")
    @Log(title = "库存产品拆解物料配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(goodsOrderMaterialsService.deleteByIds(ids));
    }
}
